package com.xbjtech.view;

import java.io.FileInputStream;
import java.util.Map;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.View;

@Component("gifView")
public class GifView implements View {

	@Override
	public String getContentType() {
		return "image/gif";
	}

	@Override
	public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		response.addHeader("Content-Disposition", "attachment;filename=xbj.gif");
		ServletOutputStream outputStream = response.getOutputStream();
		FileInputStream file = new FileInputStream(request.getSession().getServletContext().getRealPath("/abc") + "/" + model.get("file"));
		int c = file.read();
		while (-1 != c) {
			outputStream.write(c);
			c = file.read();
		}
		file.close();		
	}

}
